#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int N = 1e7+5;

char s[N];
long long cnt[55], ans = 0, num = 0;

int main(){
	scanf("%s", s);
	int lens = strlen(s);
	for(int i=0;i<lens;i++){
		if(s[i]>='a' && s[i]<='z'){
			cnt[s[i] - 'a']++;
		}else{
			cnt[s[i] - 'A' + 26]++;
		}
	}
	priority_queue<long long, vector<long long>, greater<long long>> q;
	for(int i=0;i<52;i++){
		if(cnt[i] == 0){
			continue;
		}
		q.push(cnt[i]);
		num++;
	}
	for(int i=0;i<num-1;i++){
		long long t;
		t = q.top(); q.pop();
		t += q.top(); q.pop();
		ans += t;
		q.push(t);
	}
	if(num == 1){
		ans = 1;
	}
	printf("%lld\n", ans);
	return 0;
}
